package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;
    @RequestMapping("/save")
    public String save() {

        redisTemplate.opsForValue().set("userinfo", "zhangsan");
        return "ok";
    }

    @RequestMapping("/get")
    public Object get() {
        return redisTemplate.opsForValue().get("userinfo");
    }

    @RequestMapping("/save2")
    public String save2() {
        redisTemplate.opsForHash().put("myhash", "username","lisi");
        return "ok";
    }

    @RequestMapping("/get2")
    public Object get2() {
        return redisTemplate.opsForHash().get("myhash","username");
    }
}
